home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / wschesb1.zip / SRC / INI.C < prev    next >
C/C++ Source or Header  |  1994-03-15  |  6KB  |  173 lines

  1. /*
  2.   C source for Winsock Chess
  3.   
  4.   Revision 1994-03-15
  5.   Modified by Donald Munro for use as a 2 player chess game over a 
  6.   WINSOCK layer on a TCP (or other WinSock supporting) network.
  7.   Source code and make files for MS Visual C/C++ V1.00/1.50.
  8.   February/March 1994
  9.   All GNU copyright and distribution conditions as described below and in the
  10.   file COPYING also apply to WinSock Chess.
  11.  
  12.   C source for GNU CHESS
  13.  
  14.   Revision: 1990-09-30
  15.  
  16.   Modified by Daryl Baker for use in MS WINDOWS environment
  17.  
  18.   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
  19.   Copyright (c) 1988, 1989, 1990  John Stanback
  20.  
  21.   This file is part of CHESS.
  22.  
  23.   CHESS is distributed in the hope that it will be useful, but WITHOUT ANY
  24.   WARRANTY.  No author or distributor accepts responsibility to anyone for
  25.   the consequences of using it or for whether it serves any particular
  26.   purpose or works at all, unless he says so in writing.  Refer to the CHESS
  27.   General Public License for full details.
  28.  
  29.   Everyone is granted permission to copy, modify and redistribute CHESS, but
  30.   only under the conditions described in the CHESS General Public License.
  31.   A copy of this license is supposed to have been given to you along with
  32.   CHESS so you can know your rights and responsibilities.  It should be in a
  33.   file named COPYING.  Among other things, the copyright notice and this
  34.   notice must be preserved on all copies.
  35. */
  36.  
  37.  
  38. #define STRICT 
  39. #include <windows.h>         
  40. #include <windowsx.h>
  41. #include <commdlg.h>
  42. #include <string.h>
  43. #include <stdlib.h>
  44. #include <time.h>
  45. #include <ddeml.h>
  46.  
  47. #include "winsock.h"
  48. #include "gnuchess.h"
  49. #include "defs.h"
  50. #include "chess.h"
  51. #include "saveopen.h"
  52. #include "color.h"
  53. #include "resource.h"
  54.  
  55. extern DWORD clrBackGround;
  56. extern DWORD clrBlackSquare;
  57. extern DWORD clrWhiteSquare;
  58. extern DWORD clrBlackPiece;
  59. extern DWORD clrWhitePiece;
  60. extern DWORD clrText;
  61.  
  62.  
  63. static char np08lX[] = "%08lX";
  64.  
  65. void SaveColors (void)
  66. //--------------------
  67. {  char ostring[30];
  68.  
  69.    wsprintf ( ostring, np08lX, clrBackGround);
  70.    WritePrivateProfileString ( "Colors", "BackGround",ostring,"wschess.ini");
  71.  
  72.    wsprintf ( ostring, np08lX, clrBlackSquare);
  73.    WritePrivateProfileString ( "Colors", "BlackSquare",ostring,"wschess.ini");
  74.    
  75.    wsprintf ( ostring, np08lX, clrWhiteSquare);
  76.    WritePrivateProfileString ( "Colors", "WhiteSquare",ostring,"wschess.ini");
  77.    
  78.    wsprintf ( ostring, np08lX, clrBlackPiece);
  79.    WritePrivateProfileString ( "Colors", "BlackPiece",ostring,"wschess.ini");
  80.    
  81.    wsprintf ( ostring, np08lX, clrWhitePiece);
  82.    WritePrivateProfileString ( "Colors", "WhitePiece",ostring,"wschess.ini");
  83.  
  84.    wsprintf ( ostring, np08lX, clrText);
  85.    WritePrivateProfileString ( "Colors", "Text",ostring,"wschess.ini");
  86. }
  87.  
  88. void GetStartupColors (void)
  89. //--------------------------
  90. {
  91.    char istring[30];
  92.  
  93.    SetStandardColors ();
  94.  
  95.    GetPrivateProfileString ( "Colors", "BackGround","Default",istring,
  96.                              sizeof(istring), "wschess.ini");
  97.    if (lstrcmp ( istring, "Default") != 0)  sscanf ( istring, np08lX, &clrBackGround);
  98.  
  99.    GetPrivateProfileString ( "Colors", "BlackSquare","Default",istring,
  100.                              sizeof(istring), "wschess.ini");
  101.    if (lstrcmp ( istring, "Default") != 0)  sscanf ( istring, np08lX, &clrBlackSquare);
  102.  
  103.    GetPrivateProfileString ( "Colors", "WhiteSquare","Default",istring,
  104.                              sizeof(istring), "wschess.ini");
  105.    if (lstrcmp ( istring, "Default") != 0)  sscanf ( istring, np08lX, &clrWhiteSquare);
  106.  
  107.    GetPrivateProfileString ( "Colors", "BlackPiece","Default",istring,
  108.                              sizeof(istring), "wschess.ini");
  109.    if (lstrcmp ( istring, "Default") != 0)  sscanf ( istring, np08lX, &clrBlackPiece);
  110.  
  111.    GetPrivateProfileString ( "Colors", "WhitePiece","Default",istring,
  112.                              sizeof(istring), "wschess.ini");
  113.    if (lstrcmp ( istring, "Default") != 0)  sscanf ( istring, np08lX, &clrWhitePiece);
  114.  
  115.    GetPrivateProfileString ( "Colors", "Text","Default",istring,
  116.                              sizeof(istring), "wschess.ini");
  117.    if (lstrcmp ( istring, "Default") != 0)  sscanf ( istring, np08lX, &clrText);
  118. }
  119.  
  120. void SaveHosts(HWND hdlg,char *szNewHost)
  121. //---------------------------------------
  122. { WORD i,wNoHosts;
  123.   char szEntry[20];
  124.   PSTR psz;
  125.   DWORD dwEntryLen;
  126.   BOOL bInsert=TRUE;
  127.  
  128.   WritePrivateProfileString("Hosts",NULL,NULL,"wschess.ini");
  129.   wNoHosts = (WORD)SendDlgItemMessage(hdlg,IDC_COMBO1,CB_GETCOUNT,0,0L);
  130.   _itoa(wNoHosts,szEntry,10);                            
  131.   WritePrivateProfileString("Hosts","No",szEntry,"wschess.ini");  
  132.   for (i=0; i<wNoHosts; i++)
  133.    { dwEntryLen = SendDlgItemMessage(hdlg,IDC_COMBO1,CB_GETLBTEXTLEN,(WPARAM)i,
  134.                                      (LPARAM)((LPCSTR)szEntry));
  135.      if (dwEntryLen != CB_ERR)
  136.        { psz = (PSTR)LocalAlloc(LMEM_FIXED,(WORD)dwEntryLen);
  137.          if (psz != NULL)                                
  138.            { SendDlgItemMessage(hdlg,IDC_COMBO1,CB_GETLBTEXT,(WPARAM)i,
  139.                                 (LPARAM)((LPCSTR)psz));
  140.              wsprintf((LPSTR)szEntry,"host%d",i);
  141.              WritePrivateProfileString("Hosts",szEntry,psz,"wschess.ini");
  142.              if (lstrcmpi(szNewHost,psz) == 0)
  143.                bInsert = FALSE;
  144.              LocalFree(psz);
  145.            }
  146.        }      
  147.    }
  148.   if (bInsert) 
  149.     { SendDlgItemMessage(hdlg,IDC_COMBO1,CB_INSERTSTRING,-1,
  150.                          (LPARAM)((LPCSTR)szNewHost));            
  151.       wsprintf((LPSTR)szEntry,"host%d",i);                   
  152.       WritePrivateProfileString("Hosts",szEntry,szNewHost,"wschess.ini");
  153.       _itoa(++wNoHosts,szEntry,10);
  154.       WritePrivateProfileString("Hosts","No",szEntry,"wschess.ini");  
  155.     }  
  156. }   
  157.  
  158. void GetHosts(HWND hdlg)
  159. //----------------------
  160. { char szEntry[30],szHost[80];
  161.   int i,no;
  162.  
  163.   no = GetPrivateProfileInt("Hosts","No",0,"wschess.ini");
  164.   for (i=0; i<no; i++)
  165.    { wsprintf((LPSTR)szEntry,"host%d",i);
  166.      GetPrivateProfileString("Hosts",szEntry,"NOT DEFINED HERE",
  167.                               szHost,80,"wschess.ini");
  168.      if (lstrcmp(szHost,"NOT DEFINED HERE") == 0) continue;   
  169.      SendDlgItemMessage(hdlg,IDC_COMBO1,CB_INSERTSTRING,i,
  170.                         (LPARAM)((LPCSTR)szHost));
  171.    } 
  172. }  
  173.